package org.phpgwt.tester.client.tests;

import org.phpgwt.tester.client.classes.TestObject1;
import org.phpgwt.tester.client.remote.ObjectTestService;
import org.phpgwt.tester.client.remote.ObjectTestServiceAsync;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;

public class ObjectTest extends PhpGwtTest {
	private static ObjectTestServiceAsync service = GWT.create(ObjectTestService.class);

	public static void run() {
		final TestObject1 testObject1 = new TestObject1();
		testObject1.setBooleanVal(true);
		testObject1.setByteVal((byte) 1);
		testObject1.setCharVal('m');
		testObject1.setDateVal(DateTest.getDate(2012, 7, 23));
		testObject1.setDoubleVal(2.34d);
		testObject1.setFloatVal(5.67f);
		testObject1.setIntVal(8);
		testObject1.setLongVal(91011121314l);
		testObject1.setShortVal((short) 15);
		testObject1.setStringVal("hello php");

		service.getObject1(new AsyncCallback<TestObject1>() {
			public void onSuccess(TestObject1 result) {
				printResult("getObject1", result, testObject1);
			}

			public void onFailure(Throwable caught) {
				printResult("getObject1", caught);
			}
		});

		service.sendObject1(testObject1, new AsyncCallback<Boolean>() {
			public void onSuccess(Boolean result) {
				printResult("sendObject1", result, true);
			}

			public void onFailure(Throwable caught) {
				printResult("sendObject1", caught);
			}
		});

		final TestObject1 testObject2 = new TestObject1();
		testObject2.setBooleanVal(false);
		testObject2.setByteVal((byte) 2);
		testObject2.setCharVal((char) 68);
		testObject2.setDateVal(DateTest.getDate(2000,10,20));
		testObject2.setDoubleVal(9.3113d);
		testObject2.setFloatVal(4.323f);
		testObject2.setIntVal(1313);
		testObject2.setLongVal(392737233l);
		testObject2.setShortVal((short) 21);
		testObject2.setStringVal("this is a test");
		testObject2.setTestObject1(testObject1);
		
		service.getObject2(new AsyncCallback<TestObject1>() {
			public void onSuccess(TestObject1 result) {
				printResult("getObject2", result, testObject2);
			}

			public void onFailure(Throwable caught) {
				printResult("getObject2", caught);
			}
		});

		service.sendObject2(testObject2, new AsyncCallback<Boolean>() {
			public void onSuccess(Boolean result) {
				printResult("sendObject2", result, true);
			}

			public void onFailure(Throwable caught) {
				printResult("sendObject2", caught);
			}
		});
	}
}
